using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Try_ShowMytestProduct : Shop, IRequiresSessionState
{
	protected DataList DataListClass;
	protected HtmlInputHidden BuyOnlineValue;
	protected HtmlAnchor BuyOnline;
	protected HtmlImage ImgUrlShop;
	protected HtmlGenericControl SellerInfo;
	protected Repeater Reappreason;
	protected Label LbPage;
	protected Repeater Repeater1;
	protected HtmlForm form1;
	public int UserID = 0;
	public string UserName = "";
	public string OICQ = "";
	public string ShopSkype = "";
	public string ShopMsn = "";
	public string ShopYahoo = "";
	public string Taobaowangwang = "";
	public int ProductID = 0;
	public int ShopID = 0;
	public int AppTotalCount = 0;
	public int Days = 0;
	public string StrBeginDate = "";
	public string StrEndDate = "";
	public ProductTry ProTry = new ProductTry();
	protected Shop_Product m_shop_product = null;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Init(object sender, EventArgs e)
	{
		try
		{
			Template.BindTemplateToPage(this.Page, "SaleProduct");
		}
		catch (Exception ex)
		{
			base.WriteTemErrMsg(ex.Message.ToString());
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.m_shop_product = new Shop_Product();
		if (base.Request.QueryString["ProductID"] != null)
		{
			if (base.Request.QueryString["ProductID"].ToString() != "")
			{
				try
				{
					this.ProductID = int.Parse(base.Request.QueryString["ProductID"].ToString());
				}
				catch (Exception ex)
				{
					ex.WriteErrorLog(new string[0]);
					this.WriteErrMsg("", "该试用商品不存在", "/Try/MytestList.aspx");
				}
			}
		}
		if (!base.IsPostBack)
		{
			this.GetUserName(this.ProductID);
			this.GetAllUserInfo(this.UserName);
			this.DataAppcationBind();
			this.BindRecommend();
			this.ShowProductTry();
			this.BindClass();
		}
	}
	public void DataAppcationBind()
	{
		CurrPageLinks currPageLinks = new CurrPageLinks();
		int num = 1;
		if (base.Request.QueryString["pageindex"] != null)
		{
			if (base.Request.QueryString["pageindex"].ToString() != "")
			{
				try
				{
					num = int.Parse(base.Request.QueryString["pageindex"].ToString());
				}
				catch (Exception ex)
				{
					ex.WriteErrorLog(new string[]
					{
						"正常操作"
					});
					num = 1;
				}
			}
		}
		int num2 = (num - 1) * 10;
		DataTable dataTable = this.conn.GetDataTable(string.Concat(new object[]
		{
			"select top 10 * from HLShop_TryAppcation where ApplicationID not in(select top ",
			num2,
			" ApplicationID from HLShop_TryAppcation where ProductID=",
			this.ProductID,
			") and ProductID=",
			this.ProductID
		}));
		this.AppTotalCount = dataTable.Rows.Count;
		this.Reappreason.DataSource = dataTable;
		this.Reappreason.DataBind();
		this.LbPage.Text = currPageLinks.CurrPageLink(num, 10, this.AppTotalCount, "条记录", "/Try/ShowMytestProduct.aspx?ProductID=" + this.ProductID + "&pageindex");
	}
	public void BindRecommend()
	{
		DataTable dataTable = this.conn.GetDataTable(string.Concat(new object[]
		{
			"select * from HLShop_TryProduct where IsElite=1 and TryID<>",
			this.ProductID,
			" and  SalerID=",
			this.UserID,
			" order by CreateTime desc"
		}));
		this.Repeater1.DataSource = dataTable;
		this.Repeater1.DataBind();
	}
	public int CountApplicationNum(int ProductID)
	{
		return this.conn.ExecuteCount("select count(*) from HLShop_TryAppcation where ProductID=" + ProductID);
	}
	public void ShowProductTry()
	{
		DataTable dataTable = this.conn.GetDataTable("select * from HLShop_TryProduct where TryID=" + this.ProductID);
		if (dataTable != null && dataTable.Rows.Count > 0)
		{
			if (dataTable.Rows[0]["ProductName"].ToString().Length > 20)
			{
				this.ProTry.ProductName = dataTable.Rows[0]["ProductName"].ToString().Substring(0, 20) + "...";
			}
			else
			{
				this.ProTry.ProductName = dataTable.Rows[0]["ProductName"].ToString();
			}
			this.ProTry.ClassID = int.Parse(dataTable.Rows[0]["ClassID"].ToString());
			if (dataTable.Rows[0]["BuyOnlineAddress"] != null)
			{
				this.BuyOnlineValue.Value = dataTable.Rows[0]["BuyOnlineAddress"].ToString();
				this.BuyOnline.HRef = dataTable.Rows[0]["BuyOnlineAddress"].ToString();
			}
			this.ProTry.ProductImagePath = dataTable.Rows[0]["ProductImagePath"].ToString();
			this.ProTry.BeginDate = Convert.ToDateTime(dataTable.Rows[0]["BeginDate"].ToString());
			this.ProTry.EndDate = Convert.ToDateTime(dataTable.Rows[0]["EndDate"].ToString());
			this.ProTry.ProductNum = Convert.ToInt32(dataTable.Rows[0]["ProductNum"].ToString());
			this.ProTry.marketPrice = Convert.ToDecimal(dataTable.Rows[0]["marketPrice"].ToString());
			this.ProTry.DiscountPrice = Convert.ToDecimal(dataTable.Rows[0]["DiscountPrice"].ToString());
			this.ProTry.ProductIntroduction = dataTable.Rows[0]["ProductIntroduction"].ToString();
			this.StrBeginDate = string.Concat(new string[]
			{
				this.ProTry.BeginDate.Year.ToString(),
				"-",
				this.ProTry.BeginDate.Month.ToString(),
				"-",
				this.ProTry.BeginDate.Day.ToString()
			});
			this.StrEndDate = string.Concat(new string[]
			{
				this.ProTry.EndDate.Year.ToString(),
				"-",
				this.ProTry.EndDate.Month.ToString(),
				"-",
				this.ProTry.EndDate.Day.ToString()
			});
			DateTime d = Convert.ToDateTime(this.StrBeginDate);
			DateTime d2 = Convert.ToDateTime(this.StrEndDate);
			this.Days = (d2 - d).Days;
			if (this.Days <= 0)
			{
				this.Days = 0;
			}
		}
	}
	public string BindBuyCrediet(int UserID)
	{
		return "<script type='text/javascript'>displayStar(" + this.m_shop_product.BindBuyCrediet(UserID) + ");</script>";
	}
	public string BindSalerCrediet(int UserID)
	{
		return "<script type='text/javascript'>displayStar(" + this.m_shop_product.BindSaleCrediet(UserID) + ");</script>";
	}
	protected string GetUserContance(string feilds, string userid)
	{
		string result;
		if (userid != string.Empty)
		{
			if (Text.IsNumber(userid))
			{
				if (Convert.ToInt32(userid) >= 0)
				{
					object scalar = this.conn.GetScalar(string.Concat(new object[]
					{
						"Select ",
						feilds,
						" From [HL_UserInfo] Where UserID=",
						Convert.ToInt32(userid)
					}), new IDbDataParameter[0]);
					if (scalar != null)
					{
						result = scalar.ToString();
						return result;
					}
					result = string.Empty;
					return result;
				}
			}
		}
		result = string.Empty;
		return result;
	}
	public string StrContance(string UserName)
	{
		string text = "";
		DataTable userInfo = this.GetUserInfo(UserName);
		if (userInfo != null && userInfo.Rows.Count > 0)
		{
			if (userInfo.Rows[0]["OICQ"] != null && userInfo.Rows[0]["OICQ"].ToString() != string.Empty)
			{
				string text2 = text;
				text = string.Concat(new string[]
				{
					text2,
					"<a id=\"ConectMe1_QQLink\" href=\"http://wpa.qq.com/msgrd?V=1&amp;Uin=",
					userInfo.Rows[0]["OICQ"].ToString(),
					"&amp;Site=",
					UserName,
					"&amp;Menu=yes\" target=\"_blank\"><img id=\"ConectMe1_QQImage\" src=\"http://wpa.qq.com/pa?p=1:",
					userInfo.Rows[0]["OICQ"].ToString(),
					":4\" alt=\"QQ\" style=\"border-width:0px;\" /></a>"
				});
			}
			if (userInfo.Rows[0]["ShopSkype"] != null && userInfo.Rows[0]["ShopSkype"].ToString() != string.Empty)
			{
				object obj = text;
				text = string.Concat(new object[]
				{
					obj,
					"   <a href=\"skype:",
					userInfo.Rows[0]["ShopSkype"],
					"?call\" target=\"_blank\" class=\"STYLE2\"><img src=\"../Shop/Images/skype.gif\" title=\"Skype\" width=\"20\" height=\"20\" /></a>"
				});
			}
			if (userInfo.Rows[0]["ShopMsn"] != null && userInfo.Rows[0]["ShopMsn"].ToString() != string.Empty)
			{
				object obj = text;
				text = string.Concat(new object[]
				{
					obj,
					"   <a href=\"msnim:chat?contact=",
					userInfo.Rows[0]["ShopMsn"],
					"\" target=\"_blank\" class=\"STYLE2\"><img src=\"../Shop/Images/msn.gif\" title=\"MSN\" width=\"20\" height=\"20\" /></a>"
				});
			}
			if (userInfo.Rows[0]["ShopYahoo"] != null && userInfo.Rows[0]["ShopYahoo"].ToString() != string.Empty)
			{
				object obj = text;
				text = string.Concat(new object[]
				{
					obj,
					"   <a href=\"http://edit.yahoo.com/config/send_webmesg?.target=",
					userInfo.Rows[0]["ShopYahoo"],
					"&.src=pg\" target=\"_blank\" class=\"STYLE2\"><img src=\"../Shop/Images/yahoo.gif\" title=\"Yahoo\" width=\"20\" height=\"20\" /></a>"
				});
			}
			if (userInfo.Rows[0]["Taobaowangwang"] != null && userInfo.Rows[0]["Taobaowangwang"].ToString() != string.Empty)
			{
				text += Language.Get("Common/Nothing");
			}
		}
		else
		{
			text = "未知";
		}
		return text;
	}
	public DataTable GetUserInfo(string UserName)
	{
		return this.conn.GetDataTable("select a.UserID as UID, * from HL_User as a, HL_UserInfo as b where a.UserID=b.UserID and a.UserName='" + UserName + "'");
	}
	public void GetAllUserInfo(string UserName)
	{
		DataTable userInfo = this.GetUserInfo(UserName);
		if (userInfo != null && userInfo.Rows.Count > 0)
		{
			this.UserID = int.Parse(userInfo.Rows[0]["UID"].ToString());
			this.OICQ = userInfo.Rows[0]["OICQ"].ToString();
			this.ShopSkype = userInfo.Rows[0]["ShopSkype"].ToString();
			this.ShopMsn = userInfo.Rows[0]["ShopMsn"].ToString();
			this.ShopYahoo = userInfo.Rows[0]["ShopYahoo"].ToString();
			this.Taobaowangwang = userInfo.Rows[0]["Taobaowangwang"].ToString();
			if (userInfo.Rows[0]["ShopID"] != null)
			{
				if (userInfo.Rows[0]["ShopID"].ToString() != null)
				{
					this.ShopID = int.Parse(userInfo.Rows[0]["ShopID"].ToString());
				}
			}
		}
		userInfo.Dispose();
	}
	public void GetUserName(int ProID)
	{
		DataTable dataTable = this.conn.GetDataTable("select a.UserName as UserName from HL_User as a, HLShop_TryProduct as b where a.UserID=b.SalerID and TryID=" + this.ProductID);
		if (dataTable != null && dataTable.Rows.Count > 0)
		{
			this.UserName = dataTable.Rows[0]["UserName"].ToString();
		}
		dataTable.Dispose();
	}
	public string ShowApplicationUserName(string UserID)
	{
		string result = "未知";
		DataTable dataTable = this.conn.GetDataTable("select * from HL_User where UserID=" + int.Parse(UserID));
		if (dataTable != null && dataTable.Rows.Count > 0)
		{
			result = dataTable.Rows[0]["UserName"].ToString();
		}
		dataTable.Dispose();
		return result;
	}
	public void BindClass()
	{
		DataTable dataTable = this.conn.GetDataTable("select a.ClassName as ClassName,a.ClassID as CID from HLShop_Class as a inner join  (select ClassID from HLShop_TryProduct Group by ClassID) b on a.ClassID=b.ClassID");
		this.DataListClass.DataSource = dataTable;
		this.DataListClass.DataBind();
		dataTable.Dispose();
	}
	public string GetNumber(string ClassID)
	{
		return this.conn.ExecuteCount("select count(*) from HLShop_TryProduct where ClassID=" + int.Parse(ClassID)).ToString();
	}
	public string ShowClassName(int ClassID)
	{
		string result = "";
		DataTable dataTable = this.conn.GetDataTable("select ClassName from HLShop_Class where ClassID=" + ClassID);
		if (dataTable != null && dataTable.Rows.Count > 0)
		{
			result = dataTable.Rows[0]["ClassName"].ToString();
		}
		dataTable.Dispose();
		return result;
	}
}
